package com.bestcem.xm.user.util.converter;

import com.alibaba.excel.util.StringUtils;
import com.alibaba.fastjson.JSON;
import com.bestcem.xm.user.controller.vo.user.UserInfoVO;
import com.bestcem.xm.user.entity.pojo.UserDO;
import com.bestcem.xm.user.enums.BooleanStatusEnum;
import com.bestcem.xm.user.service.dto.user.UserDTO;
import com.bestcem.xm.user.service.dto.user.UserSelfDTO;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 用户信息手工转换类
 *
 * @author qiongyu.cui <qiongyu.cui@idiaoyan.com>
 * @version v1.0
 * @date 2022/5/26 14:18
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class UserConverter {

    /**
     * 将用户信息转换成指定格式的用户信息返回
     *
     * @param userDtos 用户信息列表
     * @return java.util.List<com.bestcem.xm.user.controller.vo.user.UserInfoVO>
     * @author cuiqiongyu <qiongyu.cui@idiaoyan.cn>
     * @date 2022/05/26 14:22
     */
    public static List<UserInfoVO> userDtosToUserInfoVos(List<UserDTO> userDtos) {
        List<UserInfoVO> result = new ArrayList<>();
        if (CollectionUtils.isEmpty(userDtos)) {
            return result;
        }

        for (UserDTO userDto : userDtos) {
            UserInfoVO userInfoVO = new UserInfoVO();
            userInfoVO.setAvatar(userDto.getAvatar());
            userInfoVO.setContent(userDto.getContent());
            userInfoVO.setCreateTime(userDto.getCreateTime());
            userInfoVO.setCreatorId(userDto.getCreatorId());
            userInfoVO.setDingName(userDto.getDingName());
            userInfoVO.setDingUnionid(userDto.getDingUnionid());
            userInfoVO.setDingUserid(userDto.getDingUserid());
            userInfoVO.setEdition(userDto.getEdition());
            userInfoVO.setEmail(userDto.getEmail());
            userInfoVO.setFsName(userDto.getFsName());
            userInfoVO.setFsOpenId(userDto.getFsOpenId());
            userInfoVO.setFsUnionId(userDto.getFsUnionId());
            String showGuideRecords = userDto.getShowGuideRecords();
            if (StringUtils.isNotBlank(userDto.getShowGuideRecords())) {
                userInfoVO.setShowGuideRecords(JSON.parseArray(showGuideRecords, String.class));
            }
            userInfoVO.setUserId(userDto.getUserId());
            userInfoVO.setAcceptFlag(BooleanStatusEnum.toBoolean(userDto.getAcceptFlag()));
            userInfoVO.setBiShareFlag(BooleanStatusEnum.toBoolean(userDto.getBiShareFlag()));
            userInfoVO.setInnerFlag(BooleanStatusEnum.toBoolean(userDto.getInnerFlag()));
            userInfoVO.setLastLoginTime(userDto.getLastLoginTime());
            userInfoVO.setPhone(userDto.getPhone());
            userInfoVO.setName(userDto.getName());
            userInfoVO.setOrgId(userDto.getOrgId());
            userInfoVO.setRegisterIp(userDto.getRegisterIp());
            userInfoVO.setShowGuide(BooleanStatusEnum.toBoolean(userDto.getShowGuide()));
            userInfoVO.setShowVersion(BooleanStatusEnum.toBoolean(userDto.getShowVersion()));
            userInfoVO.setSilentId(userDto.getSilentId());
            userInfoVO.setSsoName(userDto.getSsoName());
            userInfoVO.setStatus(userDto.getStatus());
            userInfoVO.setUpdateTime(userDto.getUpdateTime());
            userInfoVO.setOperatorId(userDto.getOperatorId());
            userInfoVO.setUserName(userDto.getUserName());
            userInfoVO.setUserIndex(userDto.getUserIndex());
            userInfoVO.setQyWxName(userDto.getQyWxName());
            userInfoVO.setQyWxOpenUserid(userDto.getQyWxOpenUserid());
            userInfoVO.setQyWxUserid(userDto.getQyWxUserid());
            userInfoVO.setWxNickname(userDto.getWxNickname());
            userInfoVO.setWxOffiOpenid(userDto.getWxOffiOpenid());
            userInfoVO.setWxMiniOpenid(userDto.getWxMiniOpenid());
            userInfoVO.setWxUnionid(userDto.getWxUnionid());
            userInfoVO.setSuperFlag(userDto.getSuperFlag());
            userInfoVO.setSeniorFlag(userDto.getSeniorFlag());
            result.add(userInfoVO);
        }
        return result;
    }


    public static UserSelfDTO userSelfDO2DTO(UserDO userDO) {
        if (userDO == null) {
            return null;
        }

        UserSelfDTO userSelfDTO = new UserSelfDTO();

        userSelfDTO.setUserId(userDO.getUserId());
        userSelfDTO.setUserName(userDO.getUserName());
        userSelfDTO.setName(userDO.getName());
        userSelfDTO.setAvatar(userDO.getAvatar());
        userSelfDTO.setEmail(userDO.getEmail());
        userSelfDTO.setPhone(userDO.getPhone());
        userSelfDTO.setStatus(userDO.getStatus());
        userSelfDTO.setContent(userDO.getContent());
        userSelfDTO.setUserIndex(userDO.getUserIndex());
        userSelfDTO.setEdition(userDO.getEdition());
        userSelfDTO.setShowGuide(BooleanStatusEnum.toBoolean(userDO.getShowGuide()));
        userSelfDTO.setShowGuideRecords(userDO.getShowGuideRecords());
        userSelfDTO.setShowVersion(BooleanStatusEnum.toBoolean(userDO.getShowVersion()));
        userSelfDTO.setAcceptFlag(BooleanStatusEnum.toBoolean(userDO.getAcceptFlag()));
        userSelfDTO.setInnerFlag(BooleanStatusEnum.toBoolean(userDO.getInnerFlag()));
        userSelfDTO.setBiShareFlag(BooleanStatusEnum.toBoolean(userDO.getBiShareFlag()));
        userSelfDTO.setRegisterIp(userDO.getRegisterIp());
        userSelfDTO.setLastLoginTime(userDO.getLastLoginTime());
        userSelfDTO.setWxUnionid(userDO.getWxUnionid());
        userSelfDTO.setWxMiniOpenid(userDO.getWxMiniOpenid());
        userSelfDTO.setWxOffiOpenid(userDO.getWxOffiOpenid());
        userSelfDTO.setWxNickname(userDO.getWxNickname());
        userSelfDTO.setQyWxUserid(userDO.getQyWxUserid());
        userSelfDTO.setQyWxOpenUserid(userDO.getQyWxOpenUserid());
        userSelfDTO.setQyWxName(userDO.getQyWxName());
        userSelfDTO.setFsUnionId(userDO.getFsUnionId());
        userSelfDTO.setFsOpenId(userDO.getFsOpenId());
        userSelfDTO.setFsName(userDO.getFsName());
        userSelfDTO.setDingUserid(userDO.getDingUserid());
        userSelfDTO.setDingUnionid(userDO.getDingUnionid());
        userSelfDTO.setDingName(userDO.getDingName());
        userSelfDTO.setSsoName(userDO.getSsoName());
        userSelfDTO.setSilentId(userDO.getSilentId());
        userSelfDTO.setOrgId(userDO.getOrgId());

        return userSelfDTO;
    }

}
